﻿using BehaviorTrees;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.Xna.Framework;
namespace TestProject
{
    
    /// <summary>
    ///This is a test class for SequenceTest and is intended
    ///to contain all SequenceTest Unit Tests
    ///</summary>
	[TestClass()]
	public class SequenceTest : BaseTest
	{
		private TestContext testContextInstance;	
		/// <summary>
		///Gets or sets the test context which provides
		///information about and functionality for the current test run.
		///</summary>
		public TestContext TestContext
		{
			get
			{
				return testContextInstance;
			}
			set
			{
				testContextInstance = value;
			}
		}
		// 
		TestEntity entity;
		Sequence<TestEntity> sequence;
		#region Additional test attributes
		// 
		//You can use the following additional attributes as you write your tests:
		//
		//Use ClassInitialize to run code before running the first test in the class
		//[ClassInitialize()]
		//public static void MyClassInitialize(TestContext testContext)
		//{
		//}
		//
		//Use ClassCleanup to run code after all tests in a class have run
		//[ClassCleanup()]
		//public static void MyClassCleanup()
		//{
		//}
		//
		//Use TestInitialize to run code before running each test
		//[TestInitialize()]
		//public void MyTestInitialize()
		//{
		//}
		//
		//Use TestCleanup to run code after each test has run
		//[TestCleanup()]
		//public void MyTestCleanup()
		//{
		//}
		//
		#endregion


		/// <summary>
		///A test for Evaluate
		///</summary>
		public void EvaluateTestHelper<E>()
			where E : Entity
		{
			Sequence<E> target = new Sequence<E>(); // TODO: Initialize to an appropriate value
			E entity = default(E); // TODO: Initialize to an appropriate value
			Task<E> expected = null; // TODO: Initialize to an appropriate value
			Task<E> actual;
			actual = target.Evaluate(entity);
			Assert.AreEqual(expected, actual);
			Assert.Inconclusive("Verify the correctness of this test method.");
		}

		/// <summary>
		/// Tests if the sequence executes task proper number of times
		/// </summary>
		[TestMethod()]
		public void NumberOfSequenceExecutions()
		{
			entity = new TestEntity();
			int seqLength = 5;
			int i;

			sequence = new Sequence<TestEntity>();
			for(i=0;i<seqLength;i++)
			{
				sequence.Add(new BehaviorTrees.Action<TestEntity>(TestEntity.IncreaseX));
			};

			Run(sequence, entity);

			Assert.AreEqual(seqLength, entity.x);
			//Assert.Inconclusive("No appropriate type parameter is found to satisfies the type constraint(s) of E. " +
			//		"Please call EvaluateTestHelper<E>() with appropriate type parameters.");
		}
		/// <summary>
		/// Tests if the sequence properly stops executions if one of its task fails
		/// </summary>
		[TestMethod()]
		public void SequenceFailure()
		{
			entity = new TestEntity();
			sequence = new Sequence<TestEntity>()
			{
				new BehaviorTrees.Action<TestEntity>(TestEntity.IncreaseX),
				new BehaviorTrees.Action<TestEntity>(TestEntity.Fail),
				new BehaviorTrees.Action<TestEntity>(TestEntity.IncreaseX),
			};
			Run(sequence, entity);
			Assert.AreEqual(1, entity.x);
		}
	}
}
